<?php

namespace Wilead\IArtistBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Wilead\IArtistBundle\Entity\Job;

/**
 * Job controller.
 *
 */
class JobController extends Controller {

    /**
     * Lists all Job entities.
     *
     */
    public function indexAction() {
        $em = $this->getDoctrine()->getManager();

        $filter = $this->get('form.factory')->create(new \Wilead\IArtistBundle\Filter\JobFilterType());
        $queryBuilder = $em->getRepository('WileadIArtistBundle:Job')->createQueryBuilder('q');
        $queryBuilder->orderBy('q.created', 'DESC');
        if ($this->get('request')->query->has('submit-filter')) {
            $filter->bind($this->get('request'));
            $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($filter, $queryBuilder);
        }

        $paginator = $this->get('knp_paginator');
        $pagination = $paginator->paginate(
                $queryBuilder->getQuery(), $this->get('request')->query->get('page', 1), 20
        );

        return $this->render('WileadIArtistBundle:Job:index.html.twig', array(
                    'entities' => $pagination,
                    'filter' => $filter->createView()
        ));
    }

    public function showAction($id) {
        $em = $this->getDoctrine()->getManager();
        $entity = $em->getRepository('WileadIArtistBundle:Job')->getJobQueryBuilder($id)->getQuery()->getSingleResult();

        if (!$entity) {
            throw $this->createNotFoundException('招聘不存在');
        }

        return $this->render('WileadIArtistBundle:Job:show.html.twig', array(
                    'entity' => $entity
        ));
    }

    /**
     * Deletes a UserAlbums entity.
     */
    public function deleteAction($id) {
        $em = $this->getDoctrine()->getManager();
        $entity = $em->getRepository('WileadIArtistBundle:Job')->find($id);

        if (!$entity) {
            throw $this->createNotFoundException('Unable to find UserVideo entity.');
        }

        $em->remove($entity);
        $em->flush();

        return $this->redirect($this->generateUrl('manager_job'));
    }

}
